//
//  WPNoShowBigImageBtnCell.m
//  wobingwoyi
//
//  Created by WGP on 2016/12/5.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPNoShowBigImageBtnCell.h"
#import "WPContentModel.h"

@implementation WPNoShowBigImageBtnCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self imageView];
        self.contentView.backgroundColor = [UIColor orangeColor];
    }
    return self;
}

-(UIImageView *)iconView
{
    if (_iconView == nil)
    {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder_Image"]];
        _iconView.contentMode = UIViewContentModeScaleAspectFill;
        _iconView.clipsToBounds = YES;
        _iconView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pictureDidTap:)];
        [_iconView addGestureRecognizer:tgr];
        
        [self.contentView addSubview:_iconView];
        
        CGFloat itemWidth = (SCREEN_WIDTH - 4*10)/3.0;
        CGFloat itemHeight = itemWidth*90/112.5;
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(10);
            make.top.equalTo(self.contentView).offset(5);
            make.width.mas_equalTo(itemWidth);
            make.height.mas_equalTo(itemHeight);
        }];
    }
    return _iconView;
}

-(void)pictureDidTap:(UITapGestureRecognizer *)tgr
{
    //点击图片
    UIImage *image = self.iconView.image;
    CGFloat scale = image.size.width/image.size.height;
    
    CGFloat itemWidth = SCREEN_WIDTH-2*10;
    CGFloat itemHeight = itemWidth/scale;
    
    if (self.model.width == itemWidth)
    {
        if (self.showAllPicture)
        {
            self.showAllPicture(self.url);
        }
    }
    else
    {
        self.model.width = itemWidth;
        
        if (self.refreshCell)
        {
            self.refreshCell(self.indexPath);
        }
    }
    
}

@end
